﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using NAudio;
using NAudio.Wave;

namespace MusicMaker
{
    public class SoundPlayer
    {
        private static WaveOutEvent waveOut;
        private static BufferedWaveProvider waveProvider;
        public static void Play(Sound sound)
        {
            int size = sound.data.Length * sizeof(int);
            byte[] buffer = new byte[size];
            Buffer.BlockCopy(sound.data, 0, buffer, 0, size);
            waveProvider.AddSamples(buffer, 0, size);

            waveOut = new WaveOutEvent();
            WaveFormat waveFormat = new WaveFormat(sound.smaple_rate, 1);
            waveProvider = new BufferedWaveProvider(waveFormat);
            waveOut.Init(waveProvider);
            waveOut.Play();
        }
    }
}
